﻿using JESAI.Redis.Abstracts.Commadns;
using JESAI.Redis.Abstracts;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using JESAI.Redis.Builders;
using JESAI.Redis.Abstracts.Commands;

namespace JESAI.Redis.Extensions
{
    public static class RedisCommandBuilderExtension
    {
        public static async Task<IRedisCommand> BuildAsync(this RedisCommandBuilder commandBuilder, IConnectionBuilder connectionBuilder)
        {
            return await commandBuilder.BuildAsync(connectionBuilder);
        }

        public static async Task<IRedisCommand> BuildAsync(this IConnectionBuilder connectionBuilder)
        {
            IRedisCommandBuilder redisCommandBuilder = new RedisCommandBuilder();

            return await redisCommandBuilder.BuildAsync(connectionBuilder);
        }

        public static async Task<IRedisCommand> BuildAsync(string connectionString)
        {
            IRedisCommandBuilder redisCommandBuilder = new RedisCommandBuilder();

            return await redisCommandBuilder.BuildAsync(connectionString);
        }

        public static async Task<IRedisCommand> BuildAsync(this RedisCommandBuilder commandBuilder, string connectionString)
        {
            var connectionBuilder = ConnectionBuilder.Parse(connectionString);
            return await commandBuilder.BuildAsync(connectionBuilder);
        }
    }
}
